﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkCard.Utils;
using LinkCard.CustomerView.Common;

namespace LinkCard.CustomerView
{
    public partial class JobDetail : System.Web.UI.Page
    {
        public string LogoFilePath;
        public AppEnv _Instance = AppEnv.Instance();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            int jobID = 1;
            if (!string.IsNullOrEmpty(Page.RouteData.Values["jobid"].ToString()))
            {
                if (!int.TryParse(Page.RouteData.Values["jobid"].ToString(), out jobID))
                {
                    jobID = 1;
                }
            }
            var dt = DataHelper.SelectTable("Select * from jobs inner join company on jobs.companyID = company.companyID inner join JobLevel on jobs.JobLevelID = JobLevel.JobLevelID where JobID = " + jobID + "", false);
            if (dt.Rows.Count > 0) {
                JobPosition.Text = dt.Rows[0]["JobPosition"].ToString();
                JobDescription.Text = dt.Rows[0]["JobDescription"].ToString();
                JobRequire.Text = dt.Rows[0]["JobRequire"].ToString();
                JobSalaryLevel.Text = dt.Rows[0]["JobSalaryLevel"].ToString();
                JobType.Text = dt.Rows[0]["JobType"].ToString();
                JobDeadlineToApply.Text =Convert.ToDateTime( dt.Rows[0]["JobDeadlineToApply"]).ToString("dd/MM/yyyy");
                JobDeadlineToApply2.Text = Convert.ToDateTime(dt.Rows[0]["JobDeadlineToApply"]).ToString("dd/MM/yyyy");
                JobLevel.Text = dt.Rows[0]["JobLevelName"].ToString();
                CompanyName.Text = dt.Rows[0]["CompanyName"].ToString();
                CompanyDetail.Text = dt.Rows[0]["CompanyDetails"].ToString();
                LogoFilePath = _Instance["LogoFolderPath"] + dt.Rows[0]["CompanyLogo"].ToString();
            }
            dt = DataHelper.SelectTable("Select CityName from  Cities inner join Job_Cities on Cities.CityID = Job_Cities.CityID where JobID = " + jobID + "", false);
            string sCities = "";
            for (int i = 0; i < dt.Rows.Count; i++) {
                sCities += dt.Rows[i]["CityName"].ToString() + "<br>";
            }
            JobCity.Text = sCities;

            dt = DataHelper.SelectTable("Select IndustryName from  Industrial inner join Job_Industrial on Industrial.IndustryID = Job_Industrial.IndustryID where JobID = " + jobID + "", false);
            string sIndustries = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sIndustries += dt.Rows[i]["IndustryName"].ToString() + "<br>";
            }
            JobIndustry.Text = sIndustries;

            Page.Title = JobPosition.Text + " - Job Searching";
            Page.MetaDescription = Page.Title;
        }
    }
}